﻿using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;

public class CustomTools : MonoBehaviour {

    [MenuItem("CustomTools/StartProject &b")]
    static void startProject() {
        EditorApplication.isPlaying = !EditorApplication.isPlaying;
    }

    [MenuItem("CustomTools/Quick Apply _F1")]
    public static void quickApply()
    {

        if (Selection.gameObjects.Length > 0)
        {
            var target = Selection.gameObjects[0];
            var instanceRoot = PrefabUtility.FindRootGameObjectWithSameParentPrefab(target.gameObject);
            var targetPrefab = UnityEditor.PrefabUtility.GetPrefabParent(instanceRoot);

            PrefabUtility.ReplacePrefab(
                instanceRoot,
                targetPrefab,
                ReplacePrefabOptions.ConnectToPrefab
            );
        }
        else
        {

            Debug.LogWarning("Please select a prefab.");
        }


    }

    [MenuItem("CustomTools/Quick Toggle Active _F2")]
    public static void quickToggleActive()
    {
        EditorApplication.ExecuteMenuItem("GameObject/Toggle Active State");
    }
}
